package com.linkoog.devtools.hide_project_path.action;

import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.project.Project;
import com.linkoog.devtools.hide_project_path.persistent.ShowProjectPathSettings;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class ToggleShowProjectPathAction extends ToggleAction {

    public ToggleShowProjectPathAction() {
        super("Show Project Path");
    }

    @Override
    public boolean isSelected(@NotNull AnActionEvent e) {
        final Project project = e.getProject();
        if (project == null) return false;
        return ShowProjectPathSettings.getInstance(project).isShowProjectPath();
    }

    @Override
    public void setSelected(@NotNull AnActionEvent e, boolean state) {
        final Project project = e.getProject();
        if (project == null) return;
        ShowProjectPathSettings.getInstance(project).setShowProjectPath(state);
        ProjectView.getInstance(project).refresh();
    }

    @Override
    public @NotNull ActionUpdateThread getActionUpdateThread() {
        return ActionUpdateThread.BGT;
    }

}

